package com.inmarry.action;

import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.util.*;
import com.inmarry.model.*;
import com.inmarry.form.*;


public final class HelloAction extends Action {
    public ActionForward execute(
            ActionMapping mapping,
            ActionForm form,
            HttpServletRequest req,
            HttpServletResponse res ) throws Exception {

        
        MessageResources messages = getResources(req);

        ActionMessages errors = new ActionMessages();

        String userName = (String)((DynaActionForm)form).get("userName");

        String badUserName = "Monster";

        if ( userName.equalsIgnoreCase(badUserName) ) {
            errors.add("username",
                    new ActionMessage("hello.dont.talk.to.monster",
                    badUserName));

            saveErrors(req, errors);
            return(new ActionForward(mapping.getInput()));
        }


        PersonBean pb = new PersonBean();

        pb.setUserName(userName);
        pb.saveToPS();

        req.setAttribute(Constants.PERSON_KEY, pb);
        req.removeAttribute(mapping.getAttribute());

        return(mapping.findForward("SayHello"));



    }


}

